package cn.tedu.lbs.basic.web.controller;

import cn.tedu.lbs.basic.web.repository.BusinessRepository;
import cn.tedu.lbs.basic.web.service.BusinessService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.basic.param.BusinessParam;
import com.tarena.lbs.pojo.basic.query.BusinessQuery;
import com.tarena.lbs.pojo.basic.vo.BusiStoreVO;
import com.tarena.lbs.pojo.basic.vo.BusinessCategoryVO;
import com.tarena.lbs.pojo.basic.vo.BusinessVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理商家相关所有功能
 */
@RestController
@Slf4j
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> pageList(BusinessQuery query) throws BusinessException {
        log.info("商家后台分页,入参:{}",query);
        PageResult<BusinessVO> voPage=businessService.pageList(query);
        log.info("商家后台分页,入参:{};出参:{}",query,voPage);
        return new Result<>(voPage);
    }
    //查询商家行业分类列表
    @GetMapping("/admin/basic/business/category/list/")
    public Result<List<BusinessCategoryVO>> categoryList(){
        return new Result<>(businessService.categoryList());
    }
    //新增提交商家表单

    /**
     * springmvc框架中默认 转化json的转化器 无法将时间字符串转化成日期类型
     * startTime="2024-01-01 12:0:0"
     * {
     *     "startTime":"2024-01-01 12:0:0"
     * }
     */
    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> save(@RequestBody BusinessParam param)
        throws BusinessException{
        //save方法是幂等的,同一个商家名称不允许重复提交
        businessService.save(param);
        return Result.success();
    }
    //从活动中 查询 商家 以及商家下店铺的接口功能
    @GetMapping("/basic/business/info/detail/{id}")
    public Result<BusiStoreVO> busiStore(@PathVariable("id") Integer id)
        throws BusinessException{
        return new Result<>(businessService.busiStore(id));
    }
}
